package com.yvtian.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yvtian.admin.pojo.SysDept;
import com.yvtian.admin.dao.SysDeptMapper;
import com.yvtian.admin.service.SysDeptService;
import com.yvtian.utils.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * (sys_dept)表服务实现类
 *
 * @author long
 * @since 2024-04-06 14:28:54
 */
@Service("sysDeptService")
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {

    @Resource
    private SysDeptMapper sysDeptMapper;

    @Override
    public IPage<SysDept> findByPage(Page<SysDept> page, SysDept sysDept) {
        LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
        if (StringHelper.isNotEmpty(sysDept.getDeptName())) {
            queryWrapper.like(SysDept::getDeptName, sysDept.getDeptName());
        }
        if (StringHelper.isNotEmpty(sysDept.getStatus())){
            queryWrapper.eq(SysDept::getStatus,sysDept.getStatus());
        }
        return this.page(page, queryWrapper);
    }

    @Override
    public ArrayList<SysDept> recursionDept(Integer deptId) {
        return sysDeptMapper.recursionDept(deptId);
    }
}

